import { constants } from '../store'
import axios from 'axios'

export const changeFocus = () =>({
  type: constants.CHANGE_FOCUS
})

export const changeBlur = () =>({
  type: constants.CHANGE_BLUR
})
export const mouseEnter = () =>({
  type: constants.MOUSE_ENTER
})
export const mouseLeave = () =>({
  type: constants.MOUSE_LEAVE
})
export const clickPage = (page) =>({
  type: constants.CLICK_PAGE,
  page
})
export const getListItem = (list,totalPage) =>({
  type: constants.GET_LIST,
  list,
  totalPage: Math.ceil(totalPage / 10)
})

export const getList = () =>{
  return (dispatch) => {
    axios.get('/api/list.json').then((res) => {
      dispatch(getListItem(res.data,res.data.length))
    }).catch(() => {
      console.log('error')
    })
  }
}
